#ifndef  _XINFOMATLAYOUTMANAGER_H
#define _XINFOMATLAYOUTMANAGER_H

#include <qwidget.h>
#include <qfile.h>
#include <qstring.h>
#include <qvector.h>
#include <qdatetime.h>
#include "infomatcommon.h"
#include <qtimer.h>
#include <xwritelogexport.h>
#include "xdatabootconf.h"

class XHtmlPlayer;
class XMoviePlayer;
class XDataBootConf;
class XInfomatLayoutManager :public QObject
{
	Q_OBJECT
		
public:
	XInfomatLayoutManager(QObject *parent=0 );//, Qt::WFlags f=0);
	~XInfomatLayoutManager();

	int doRoutine(const bool needSwitchPartial=false);
	int doPlu(const int PluNo, const bool needSwitchPartial=false);
	int doHalt();
	int doResume();
	int doEnterMenuMode();
	int doExitMenuMode();
	int doEnterScreenSaver();
	int doExitScreenSaver();
	int doQueue();
private slots:
	void onPlayRoutineDone(int index);
	void onPlayPlu(int index);
	void onQueueDown();
	void onCPlayerIdle();
	void onCheckPlayers();
signals:
	void sgUpdateList(int id);
	void sgQueueWidgetRepaint();
	void sgWMRepaint();
protected:
	int  buildRoutineList();   //Playlist
	int  updatePlayList();                     //Playlist
	int  buildPluList(const int plu);    //Plu (runtime building)
	void debugOutput(void);	
	void startRoutinePlay();
	void startPluPlay();
	int isPluValid(const int PluNo);
	void setScreenMode(const int  screenMode); 
	void setPlayersGeometryWithLayout();
	void clearRoutinePlayConnections();
	void clearPluPlayConnections();
	void processInfomatEvents();
	int stopPlayersAndHide();

private:
	XHtmlPlayer     *m_xHtmlPlayer;
	XMoviePlayer    *m_xMoviePlayer;
	QVector<STFileInfo>	m_playlist, m_plulist, m_tempPluList;
	STFileInfo m_fileInfo;   //current playing file infomation
	QDateTime m_playListLastModified;
	int  	m_playIndex, m_pluIndex;
	int 	m_defaultTimeout;                                  
	int  	m_layout;
	int 	m_currentPlu;
	int     m_screenMode;
	int     m_event;
	bool 	m_isPlayingPlu;     //indicate current PLU state, avoid playing same plu in the same time
	bool    m_isCPlayerIdle;
	bool    m_isHtmlIdle;
	bool    m_isTempPassPluValid;   
	bool    m_isPassPluValid;   //indicate PLU checking pass isPluValid only
	bool    m_isPlayersValid;
	bool    m_needSwitchPartial;
	QTimer  m_tmCheckPlayers;
	XDataBootConf m_xbootConf;

private:
	enum EUpdateList {
		EUpdateRoutineList = -10,
		EUpdatePluList,
		EFileNotExist,
	};
	enum EScreenModeState {
		EFullScreen = 0,
		EPartialScreen,
	};
	enum EScreenModeSwitch {
		EScreenModeOff =0,
		EScreenModeOn
	};
	enum EInfomatEvents {
		ENoEvent = -1,
		ERoutine,
		EPlu,
		EQueue,
		EEnterMenuMode,
		EExitMenuMode,
		EEnterScreenSaver,
		EExitScreenSaver,
	};
	inline bool isPicture(const char* in_file)  {
		assert (NULL!=in_file);
		QString file = QString(in_file);
		if ( file.endsWith("JPEG") || file.endsWith("jpeg") ||
			 file.endsWith("JPG")  || file.endsWith("jpg")  ||
			 file.endsWith("BMP")  || file.endsWith("bmp")  ||
			 file.endsWith("GIF")  || file.endsWith("gif")  ||
			 file.endsWith("PNG")  || file.endsWith("png")  ){
			return true;
		} else {
			return false;
		}
	
	}
	inline bool isFileExist(const char* in_file) {
		bool isExist = false;
		if (!QFile::exists(QString(in_file))) {
			LOG_E("file:%s is not existed", in_file);
			isExist = false;
		} else {
//			LOG_T("file:%s is existed", in_file);
			isExist = true;
		}
		return isExist;
	}

};  // End of Class XInfomatLayoutManager
#endif
